<?php
class Teacher extends Zend_Db_Table{
    protected $_name ="teacher";
	protected $_primary = 'teacher_id';

    public function getTopTeachers(){
		$select = $this->select();
		$select->limit('10');
		$select->order('teacher_id desc');
		return $this->fetchAll($select)->toArray();
    }

    public  function getAllteacgertInArray($array){
		$where=" teacher_id in (".implode(',',$array).")";
		$select = $this->select();
		$select->where($where);
		$select->order('teacher_id desc');
		$sql = $select->__toString();

		return $this->fetchAll($select)->toArray();
    }
	
    // 查询所有teacher
    public function getAllTeachers($page,$perpage,$search_name){
		$where = "1=1";
		if($search_name!=""){
		  $where.=" and name like '%$search_name%'";
		}
		$select = $this->select();
		$select->where($where);
		if($page!=""){
		$select->limitPage($page,$perpage);
		}
		$select->order('teacher_id desc');
		return $this->fetchAll($select)->toArray();
    }

	//根据老师的名字模糊查询教师表
	public function getteacherLikename($teacher_name){
		$select = $this->select();
		$select->where("name like %".$teacher_name."%");
		return $this->fetchAll($select)->toArray();
	}
   
	//根据teacher_id 查询teacher
	public function getteacherByteacher_id($teacher_id){
		$select = $this->select();
		$select->where("teacher_id='".$teacher_id."'");
		return $this->fetchAll($select)->toArray();
	}
	
	//根据teacher_name 查询teacher
	public function getTeacherByteacher_name($teacher_name){
		$select = $this->select();
		$select->where("name='".$teacher_name."'");
		return $this->fetchAll($select)->toArray();
	}

	//更新teacher
    public function updateteacherByteacher_id($array,$teacher_id){
		$db = $this->getAdapter();
		$where=$db->quoteInto('teacher_id = ?', $teacher_id);
		$this->update($array, $where);
	}
	
	//删除teacher
	public function delteacherByteacher_id($teacher_id){
		$where = 'teacher_id = '. $teacher_id;
		$this->delete($where);
		return true;
	}
}
?>
